<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
    <link rel="stylesheet" href="../assets/app/css/app.css" />
    <style>.common-btn {
position:absolute;
right:0px;
margin-top: -17px;
line-height: 32px;
height: 32px;
}</style>
<body style="background:#fff !important;">
<!--通用顶部-->
<div id="ios-top-box">
    <div id="header" class="bar bar-nav">
    <div class="titlebar">
    <a href="javascript:appClose('gtbase',api);"><i class="iconfont iconline-arrow-left"></i></a>
    <h1 class="title">组团众筹</h1>
    <a class="icon iconline-menu pull-right" href="javascript:cate();" style="top:12px;"></a>
    </div>
    </div>
</div>
<!--通用顶部结束-->
<header class="bar bar-nav box_shadow head_a" style="margin-top:64px;padding-left:5px;padding-right:5px;top:0px !important;">
    <a href="javascript:SwitchBtn('default_list');" style="width:20%;" class="selected_bottom jx">即将揭晓</a>
    <a href="javascript:SwitchBtn('list_new');" style="width:20%;" class="lastnew">最新</a>
    <a href="javascript:SwitchBtn('list_renqi');" style="width:20%;" class="renqi">人气</a>
    <a href="javascript:SwitchBtn('list_price');" style="width:20%;" id="listprice">价格</a>
    <a href="javascript:cate();" style="width:20%;" id="catename" style="overflow:hidden;">商品分类</a>
</header>

<section style="margin-top:95px !important;">

<div class="scroller create_goods container" style="max-width: 640px;">

<div class="goodslist" id="default_list" style="margin-top:33px;">
</div>

<div class="goodslist" id="list_new" style="margin-top:33px;display: none;">
</div>

<div class="goodslist" id="list_price" style="margin-top:33px;display: none;">
</div>

<div class="goodslist" id="list_renqi" style="margin-top:33px;display: none;">
</div>

<div class="goodslist" id="list_categoods" style="margin-top:33px;display: none;">
</div>

<div style="display:none;">
<ul class="search-ul load-more">
<li><button class="btn btn-block btn-more" id="loadmore">加载更加</button></li>
</ul> 
</div>
</div>     
</section>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
var isHide = {
  downLoad : 0, //0 最新揭晓，1最新，2人气，3价格
  team_cateid:0,
  team_catename:'全部',
};

//打开商品详情
function openGoods(goods_id){
	if(!goods_id) api.alert({'msg':'参数错误'});
	localData.set('team_goods_id',goods_id);
	api.openWin({
		name:'gbuy',
		url:'./gbuy.html',
		reload:true
	});
}

apiready = function(){
   var header = $api.byId('header');
	if(api.connectionType == 'none'){
		api.showProgress({
		     title : '未连接网络',
		     text : ''
		 });
		return false;
	}else{
	   api.showProgress({
	         title : '加载中',
	         text : ''
	   });
		setTimeout(function(){
			api.hideProgress();
		},15000);
	}
	
	setTimeout(function(){
		api.setRefreshHeaderInfo({
		    visible: true,
		    loadingImg: 'widget://image/refresh.png',
		    bgColor: '#fff',
		    textColor: '#333',
		    textDown: '下拉刷新...',
		    textUp: '松开刷新...',
		    showTime: true
		}, function(ret, err ){
			if(isHide.downLoad == 0){
				default_list();
			}else if(isHide.downLoad == 1){
				list_new();
			}else if(isHide.downLoad == 2){
				list_price();
			}else if(isHide.downLoad == 3){
				list_renqi();
			}
		});
	},500);

default_list();

};

function default_list(){
	isHide.downLoad = 0;
    var order_type = 10; //默认排序方式
    var page = 1;
    var flag = true;
    var tag = 'list';
    
    if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
    	tag = isHide.team_cateid;
    }
    
    ajaxData(order_type,page,flag,tag); 
    function ajaxData(order_type,page,flag,tag){
        order_type = 10;
        //$('.load-more').hide();
        $('.btn-more').text('加载中...');
        GetJPData(config.url+'/app.php?act=grouplistajax&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
	        api.refreshHeaderLoadDone();
            var txt = '';
            var html = '';
            for(var i=0; i < json.length; i++){
                if(json[i]['title'] == undefined){
                    flag = false;
                    $('.btn-more').text('已经到底了');
                    if(json[i]['sum'] == 0){
                        txt = '暂无数据';
                        if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
                        	$('#list_categoods').html('<p style="text-align:center;padding:10px;">'+txt+'</p>').fadeIn('fast');
                        }
                    }
                    break;
                }                
				html += '<ul class="search-ul"><li>';
				html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url+'/'+json[i]['thumb'] +'" /></a></div>';
				html += '<div class="search_goods_info">';
				html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
				html += '<div class="goods_info_bottom"><div class="goods_con">';
				html += '<p style="margin-top:5px;"><span class="left">总需人次：'+json[i]['zongrenshu']+'</span><br/><span class="left">价值：'+json[i]['money']+'</span></p>';
				html += '<button class="common-btn" onclick="openGoods('+json[i]['id']+');">我要组团</button></div>';
				html += '</div></div></li></ul>';
                
            }
            $('#default_list').html(html);
            setTimeout(function(){
                lyzimg();
                api.hideProgress();
                if(flag == false){
                    if(txt == ''){
                    $('.btn-more').text('已经到底了');
                    }else{
                        $('.btn-more').text(txt);
                        $('.container').width($(window).width());
                    }
                }else{
                    $('.container').width('auto');
                    $('.btn-more').text('加载更多');
                    }
                $('.load-more').show();
            },1000);
        },false);
    }
    
    //加载更多
    $('#loadmore').click(function(){
        if(flag == false){
            return false;
         }
        page += 1;
        flag = true;
        if($(this).text() == '已经到底了'){
            return false;
        }else{
            ajaxData(order_type,page,flag,tag);
        }
    });
}

function list_new(){
isHide.downLoad = 1;
var order_type = 40; //默认排序方式
var page = 1;
var flag = true;
var tag = 'list';
if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
	tag = isHide.team_cateid;
}
ajaxData(order_type,page,flag,tag);
api.showProgress({title : '加载中',text : ''});

function ajaxData(order_type,page,flag,tag){
    //$('.load-more').hide();
    $('.btn-more').text('加载中...');
    GetJPData(config.url+'/app.php?act=grouplistajax&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
    	api.refreshHeaderLoadDone();
        var txt = '';
        var html = '';
        for(var i=0; i < json.length; i++){
            if(json[i]['title'] == undefined){
                flag = false;
                $('.btn-more').text('已经到底了');
                if(json[i]['sum'] == 0){
                    txt = '暂无数据';
                    if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
                    	$('#list_categoods').html('<p style="text-align:center;padding:10px;">'+txt+'</p>').fadeIn('fast');
                    }
                }
                break;
            }
			html += '<ul class="search-ul"><li>';
			html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url+'/'+json[i]['thumb'] +'" /></a></div>';
			html += '<div class="search_goods_info">';
			html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
			html += '<div class="goods_info_bottom"><div class="goods_con">';
			html += '<p style="margin-top:5px;"><span class="left">总需人次：'+json[i]['zongrenshu']+'</span><br/><span class="left">价值：'+json[i]['money']+'</span></p>';
			html += '<button class="common-btn" onclick="openGoods('+json[i]['id']+');">我要组团</button></div>';
			html += '</div></div></li></ul>';
        }
        setTimeout(function(){
            $('#list_new').html(html);
            lyzimg();
            api.hideProgress();
            if(flag == false){
                if(txt == ''){
                $('.btn-more').text('已经到底了');
                }else{
                    $('.btn-more').text(txt);
                    $('.container').width($(window).width());
                }
            }else{
                $('.container').width('auto');
                $('.btn-more').text('加载更多');
                }
            $('.load-more').show();
        },1000);
    });
}

//加载更多
$('#loadmore').click(function(){
    if(flag == false){
        return false;
     }
    page += 1;
    flag = true;
    if($(this).text() == '已经到底了'){
        return false;
    }else{
        ajaxData(order_type,page,flag,tag);
    }
});

}


function list_renqi(){
isHide.downLoad = 2;
var order_type = 20; //默认排序方式
var page = 1;
var flag = true;
var tag = 'list';
if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
	tag = isHide.team_cateid;
}
ajaxData(order_type,page,flag,tag);
api.showProgress({title : '加载中',text : ''});

function ajaxData(order_type,page,flag,tag){
    if(flag ==  false){
        return;
    }
    $('.btn-more').text('加载中...');
    GetJPData(config.url+'/app.php?act=grouplistajax&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
    	api.refreshHeaderLoadDone();
        var txt = '';
        var html = '';
        for(var i=0; i < json.length; i++){
            if(json[i]['title'] == undefined){
                flag = false;
                $('.btn-more').text('已经到底了');
                if(json[i]['sum'] == 0){
                    txt = '暂无数据';
                    if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
                    	$('#list_categoods').html('<p style="text-align:center;padding:10px;">'+txt+'</p>').fadeIn('fast');
                    }
                }
                break;
            }
			html += '<ul class="search-ul"><li>';
			html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url+'/'+json[i]['thumb'] +'" /></a></div>';
			html += '<div class="search_goods_info">';
			html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
			html += '<div class="goods_info_bottom"><div class="goods_con">';
			html += '<p style="margin-top:5px;"><span class="left">总需人次：'+json[i]['zongrenshu']+'</span><br/><span class="left">价值：'+json[i]['money']+'</span></p>';
			html += '<button class="common-btn" onclick="openGoods('+json[i]['id']+');">我要组团</button></div>';
			html += '</div></div></li></ul>';
        }
        setTimeout(function(){
            $('#list_renqi').html(html);
            lyzimg();
            api.hideProgress();
            if(flag == false){
                if(txt == ''){
                $('.btn-more').text('已经到底了');
                }else{
                    $('.btn-more').text(txt);
                    $('.container').width($(window).width());
                }
            }else{
                $('.container').width('auto');
                $('.btn-more').text('加载更多');
                }
            $('.load-more').show();
        },1000);
    });
    
}

//加载更多
$('#loadmore').click(function(){
    if(flag == false){
        return false;
     }
    page += 1;
    flag = true;
    if($(this).text() == '已经到底了'){
        return false;
    }else{
        ajaxData(order_type,page,flag,tag);
    }
});

}

function list_price(){
isHide.downLoad = 3;
var order_type = 50; //默认排序方式
var page = 1;
var flag = true;
var tag = 'list';
if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
	tag = isHide.team_cateid;
}
ajaxData(order_type,page,flag,tag);
function ajaxData(order_type,page,flag,tag){
    if(flag ==  false){
        return;
    }
    api.showProgress({title : '加载中',text : ''});
    $('.btn-more').text('加载中...');
    GetJPData(config.url+'/app.php?act=grouplistajax&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
    	api.refreshHeaderLoadDone();
        var txt = '';
        var html = '';
        for(var i=0; i < json.length; i++){
            if(json[i]['title'] == undefined){
                //flag = false;
                $('.btn-more').text('已经到底了');
                if(json[i]['sum'] == 0){
                    txt = '暂无数据';
                    if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
                    	$('#list_categoods').html('<p style="text-align:center;padding:10px;">'+txt+'</p>').fadeIn('fast');
                    }
                }
                break;
            }
			html += '<ul class="search-ul"><li>';
			html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url+'/'+json[i]['thumb'] +'" /></a></div>';
			html += '<div class="search_goods_info">';
			html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
			html += '<div class="goods_info_bottom"><div class="goods_con">';
			html += '<p style="margin-top:5px;"><span class="left">总需人次：'+json[i]['zongrenshu']+'</span><br/><span class="left">价值：'+json[i]['money']+'</span></p>';
			html += '<button class="common-btn" onclick="openGoods('+json[i]['id']+');">我要组团</button></div>';
			html += '</div></div></li></ul>';
        }
        setTimeout(function(){
            $('#list_price').html(html);
            lyzimg();
            api.hideProgress();
            if(flag == false){
                if(txt == ''){
                $('.btn-more').text('已经到底了');
                }else{
                    $('.btn-more').text(txt);
                    $('.container').width($(window).width());
                }
            }else{
                $('.container').width('auto');
                $('.btn-more').text('加载更多');
                }
            $('.load-more').show();
        },1000);
    });

}

//价格
var price = 1;
$('body').on('click','.price',function(){
    if(price == 1){
        order_type = 50;
        price = 2;
        page = 1;
    }else if(price == 2){
        order_type = 60;
        price = 1;
        page = 1;
    }
    flag = true;
    tag = 'list';
    if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
    	tag = isHide.team_cateid;
    }
    $('#list_price').html('');
    $('.load-more').hide();
    ajaxData(order_type,page,flag,tag);
});

//加载更多
$('#loadmore').click(function(){
    if(flag == false){
        return false;
     }
    page += 1;
    flag = true;
    if($(this).text() == '已经到底了'){
        return false;
    }else{
        ajaxData(order_type,page,flag,tag);
    }
});

};

function jsFun(){
	setTimeout(function(){
		var team_cateid = localData.get('team_cateid');
		var team_catename = localData.get('team_catename');
		if(!team_cateid){
			api.alert({msg:'参数错误'});
			return;
		}
		$('#catename').text(team_catename);
		isHide.team_cateid = team_cateid;
		isHide.team_catename = team_catename;
		isHide.downLoad = 0;
		var order_type = 30; //默认排序方式
		var page = 1;
		var flag = true;
		var tag = team_cateid;
    	isLoad.listNew = true;
    	isLoad.listRenqi = true;
    	isLoad.listPrice = true;
    	isLoad.selected = 'all';
		if(team_cateid == 'all'){
			tag = 'list';
			$('#default_list').html('');
			$('#list_renqi').html('');
			$('#list_price').html('');
			$('#list_new').html('');
		}
		
		ajaxData(order_type,page,flag,tag);
		function ajaxData(order_type,page,flag,tag){
		    if(flag ==  false){
		        return;
		    }
		    api.showProgress({title:'加载中',text:''});
		    $('.btn-more').text('加载中...');
		    GetJPData(config.url+'/app.php?act=grouplistajax&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
		    	api.refreshHeaderLoadDone();
		        var txt = '';
		        var html = '';
		        for(var i=0; i < json.length; i++){
		            if(json[i]['title'] == undefined){
		                //flag = false;
		                $('.btn-more').text('已经到底了');
		                if(json[i]['sum'] == 0){
		                    txt = '暂无数据';
		                    $('#list_categoods').html('<p style="text-align:center;padding:10px;">'+txt+'</p>').fadeIn('fast');
		                }
		                break;
		            }
					html += '<ul class="search-ul"><li>';
					html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url+'/'+json[i]['thumb'] +'" /></a></div>';
					html += '<div class="search_goods_info">';
					html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
					html += '<div class="goods_info_bottom"><div class="goods_con">';
					html += '<p style="margin-top:5px;"><span class="left">总需人次：'+json[i]['zongrenshu']+'</span><br/><span class="left">价值：'+json[i]['money']+'</span></p>';
					html += '<button class="common-btn" onclick="openGoods('+json[i]['id']+');">我要组团</button></div>';
					html += '</div></div></li></ul>';
		        }
		        setTimeout(function(){
		        	$('.goodslist').fadeOut('fast');
		            $('#list_categoods').html(html).fadeIn('fast');
		            lyzimg();
		            api.hideProgress();
		            if(flag == false){
		                if(txt == ''){
		                $('.btn-more').text('已经到底了');
		                }else{
		                    $('.btn-more').text(txt);
		                    $('.container').width($(window).width());
		                }
		            }else{
		                $('.container').width('auto');
		                $('.btn-more').text('加载更多');
		                }
		            $('.load-more').show();
		        },1000);
		    });
		}
	},30);
}

//商品分类
function cate(){
    var header = $api.byId('header');
    //适配iOS 7+，Android 4.4+状态栏
    $api.fixStatusBar(header);
    var headerPos = $api.offset(header);
    var main = $api.byId('main');
    var mainPos = $api.offset(main);
    api.openFrame({
        name: 'cate',
        url: './cate2.html',
        rect: {
            x: 0,
            y: 0,
            w: 'auto',
            h: 'auto'
        },
        pageParam: {
            name: 'cate'
        },
        bounces: false,
        bgColor: 'rgba(0,0,0,0)',
        vScrollBarEnabled: true,
        hScrollBarEnabled: false
    });
}

var isLoad = {
    listNew : true,
    listRenqi : true,
    listPrice : true,
    selected : 'default_list',
};
function SwitchBtn(page){
	if(isHide.team_cateid != 'all'){
	    if(isLoad.selected == page){
	        return;
	    }
	}
    isLoad.selected = page;
    if(isHide.team_cateid == 'all'){
    	isLoad.listNew = true;
    	isLoad.listRenqi = true;
    	isLoad.listPrice = true;
    }
    
    $('.goodslist').hide();
    $('#'+page).stop().animate({opacity : 'show'}, 'fast');
    if(page == 'list_new' && isLoad.listNew){
        isLoad.listNew = false;
        list_new();
    }else if(page == 'list_renqi' && isLoad.listRenqi){
        isLoad.listRenqi = false;
        list_renqi();
    }else if(page == 'list_price' && isLoad.listPrice){
        isLoad.listPrice = false;
        $('#listprice').addClass('price');
        list_price();
    }else if(isHide.team_cateid != 0 && isHide.team_cateid != 'all'){
    	default_list();
    }
}

$('.head_a a').click(function(){
	if($(this).attr('id') == 'catename') return;
    $('.head_a a').removeClass('selected_bottom');
    $(this).addClass('selected_bottom');
});
</script>
</html>